package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelsCollection;
import cn.wolfcode.trip.base.mapper.TravelsCollectionMapper;
import cn.wolfcode.trip.base.service.ITravelCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelCollectionImpl implements ITravelCollectionService {
    @Autowired
    private TravelsCollectionMapper travelsCollectionMapper;

    @Override
    public void saveTravelCollectionToUser(Long userId, Long travelId) {
        //先查询,
        TravelsCollection travelsCollection=travelsCollectionMapper.getTravelCollectionToUser(userId,travelId);
        //如果有数据就跳过
        if(travelsCollection==null){
            travelsCollectionMapper.saveTravelCollectionToUser(userId,travelId);
        }
    }

    @Override
    public void deleteTravelCollectionToUser(Long userId, Long travelId) {
        //先查询,
        TravelsCollection travelsCollection=travelsCollectionMapper.getTravelCollectionToUser(userId,travelId);
        //如果有数据就跳过
        if(travelsCollection!=null){
            travelsCollectionMapper.deleteTravelCollectionToUser(userId,travelId);
        }

    }

    @Override
    public String getNewsForUser(Long userId, Long travelId) {
        TravelsCollection travelsCollection=travelsCollectionMapper.getTravelCollectionToUser(userId,travelId);
        if(travelsCollection==null){
            return "FALSE";
        }
        return "TRUE";
    }

    @Override
    public List<TravelsCollection> getAllTravelCollectionsByUser(Long userId) {
        List<TravelsCollection> TravelsCollections= travelsCollectionMapper.getAllTravelCollectionsByUser(userId);

        return TravelsCollections;
    }
}
